﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Exhibition.RenderTemplete.Controls;
using Exhibition.Common.Helper;
using Exhibition.Dao.ViewModel;
using Exhibition.Service;

namespace Exhibition.Manage
{
    public partial class RoleDetail : BaseAdminPage
    {
        RoleModel model = new RoleModel();
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                hfId.Value = reqID.ToString();
                GetRole();
            }

        }

        private void GetRole()
        {

            model = CenterService.roleService.GetOneById(reqID);
            if (model != null)
            {

                //角色名称
                txtRoleName.Value = model.RoleName.ToString();

                //角色描述
                txtRoleDesc.Text = model.RoleDesc.ToString();

                //是否启用
                rdoUsed.SelectedValue = model.IsUsed.ToString();

                //排序
                txtOrderId.Text = model.OrderId.ToString();

            }

        }

        /// <summary>
        /// 保存一条数据
        /// <summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {

            model = string.IsNullOrEmpty(hfId.Value)|| hfId.Value=="0" ? new RoleModel() : CenterService.roleService.GetOneById(Convert.ToInt32(hfId.Value));
            //角色名称
            model.RoleName = txtRoleName.Value;

            //角色描述
            model.RoleDesc = txtRoleDesc.Text;

            //是否启用
            model.IsUsed = Convert.ToInt32(rdoUsed.SelectedItem.Value);

            //排序
            model.OrderId = Convert.ToInt32(txtOrderId.Text);

            model.Funcs = hidRole.Value;
            model.CreateUserId = model.CreateUserId == 0 ? AdminUser.Id : model.CreateUserId;
            if (CenterService.roleService.Save(model) > 0)
            {
                JsHelper.Unblock(this, CommFunMsg.GetMessage("a0001", Lan.zh));

            }
            else {
                JsHelper.Alert(this, CommFunMsg.GetMessage("e0001", Lan.zh));
            }

        }

    }

}